package com.gao.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 基于代码方式配置异常统一处理
 *
 * @author GaoXi
 * @date 2021/8/17 19:19
 */
@ControllerAdvice
public class MyAdvice {

    @ExceptionHandler({ArithmeticException.class, NullPointerException.class})
    public String handlerEx(Exception ex, Model model) {
        model.addAttribute("ex", ex);
        return "fail";
    }

}
